﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_Modes;
using Zor_IDAL;
using Zor_Tools;
using System.Data;
using Dapper;
namespace Zor_DAL
{
    public class Zor_Invoice_DAL<T> where T : class
    {
        /// <summary>
        /// 录入发票号
        /// </summary>
        /// <param name="accpid">受理单ｉｄ</param>      
        /// <param name="In_Id">发票号主键ｉｄ</param>
        /// <param name="acttualtax">税金</param>
        /// <returns></returns>
        public static BaseAnswer UpdateInvoice(double Grsds, double Fcs, int In_Id, int accpid, int pt_Id, string InNumBer, double acttualtax)
        {
            
            List<string> lstsql = new List<string>();         
            //更新审核状态录入时间，录入人
            lstsql.Add(string.Format("if  exists(select In_Id  from [Zor_Invoice] where In_Id =" + In_Id + " ) update [Zor_Invoice] set In_Number='" + InNumBer + "', In_State=1,In_Date=" + TimeHelper.ToTimeStamp(DateTime.Now) + ",In_UserId=" + RequestSession.GetSessionUser().User_Id + " where In_Id=" + In_Id + ""));
            //更新受理单状态
            lstsql.Add(string.Format("update [Zor_Acceptance] set Acceptance_State=7 where Acceptance_Id=" + accpid + ""));
            //汇总表增加数据
            lstsql.Add(string.Format("insert into Zor_Summary(In_Id,Grsds,Fcs,Sm_State,Sm_ActtualTax) values (" + In_Id + "," + Grsds + "," + Fcs + ",0," + acttualtax + ")"));
            BaseAnswer bar = DapperTransaction.DoTransaction(lstsql);
            return bar;
        }
        /// <summary>
        /// 修改录入发票号
        /// </summary>
        /// <param name="InNumBer">发票号</param>      
        /// <param name="In_Id">发票号主键ｉｄ</param>
        /// <returns></returns>
        public static BaseAnswer UpdateInvoiceNum(int In_Id, string InNumBer)
        {
            var sql = "if  exists(select In_Id  from [Zor_Invoice] where In_Id =@In_Id ) ";
                sql+= "update [Zor_Invoice] set In_Number=@In_Number  where In_Id = @In_Id";
            BaseAnswer bar = DapperEdit<T>.DoEdit(sql, new Zor_Invoice { In_Number = InNumBer, In_Id = In_Id });
            return bar;
        }
    }
}
